/*
 *  BrokerageFirm.cpp
 *  StrategyInspector
 *
 *  Created by jiro on 12/08/11.
 *  Copyright 2012 jiro music. All rights reserved.
 *
 */

#include "BrokerageFirm.h"


NSString* BrokerageFirm::tableName()
{
	return kText_BrokerageFirmTable;
}

NSString* BrokerageFirm::queryCreateTable()
{
	NSString* s = [ NSString stringWithFormat: 
		@"create table %@ ( %@ %@, %@ %@, %@( %@ ) );",
		BrokerageFirm::tableName(),
		kText_Code, kText_Serial,
		kText_Name, kText_Text,
		kText_PrimaryKey, kText_Code ];
	return s;
}

NSString* BrokerageFirm::queryInsertInitialValues()
{
	NSString* names[] =
	{
		@"GMOクリック証券株式会社", 
		@"カブドットコム証券株式会社",
	};
	NSMutableString* s = [ NSMutableString stringWithFormat:
		@"insert into %@ " ];
	for ( int i = 0, count = sizeof( names ) / sizeof( NSString* ); i < count; i++ )
	{
		[ s appendFormat: @"( '%@' )", names[ i ] ];
		if ( i != count - 1 )
		{
			[ s appendString: @", " ];
		}
	}
	[ s appendString: @";" ];
	return s;
}

NSString* BrokerageFirm::querySelectAll( const std::vector< ClauseNode >& clauses )
{
	NSString* s = DbTableEntry::querySelectAll( tableName(),  clauses );
	return s;
}

NSString* BrokerageFirm::querySelect( const std::vector< FieldNode >& fieldNodes, const std::vector< ClauseNode >& clauses )
{
	NSString* s = DbTableEntry::querySelect( fieldNodes, tableName(),  clauses );
	return s;
}

BrokerageFirm::BrokerageFirm()
{}
	
BrokerageFirm::BrokerageFirm( int index, NSString* name )
	: index( index ),
	  name( name )
{}

NSString* BrokerageFirm::queryInsert() const
{
	NSString* s = [ NSString stringWithFormat:
		@"insert into %@ values %@;",
		BrokerageFirm::tableName(),
		queryInsertValue() ];
	return s;
}

NSString* BrokerageFirm::queryInsertValue() const
{
	NSString* s = [ NSString stringWithFormat:
		@"( %d, %@ )", index, name ];
	return s;
}
